package com.gc.web.controller.api;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gc.business.domain.*;
import com.gc.business.service.*;
import com.gc.common.constant.BusinessConstants;
import com.gc.common.constant.Constants;
import com.gc.common.utils.DateUtils;
import com.gc.common.utils.GeTuiUtils;
import com.gc.common.utils.IdUtils;
import com.gc.common.utils.StringUtils;
import com.gc.framework.web.base.ApiBaseController;
import com.gc.system.domain.SysRole;
import com.gc.system.domain.SysUser;
import com.gc.system.service.ISysDictDataService;
import com.gc.system.service.ISysUserService;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 电梯困人管理 控制层
 *
 * @author liujinteng
 * @date 2020-11-17
 */
@Slf4j
@Controller
@RequestMapping("/api/elevatorTiring")
public class ApiElevatorTiringController extends ApiBaseController {

    @Autowired
    private IElevatorTiringService elevatorTiringService;

    @Autowired
    private IElevatorFaultService elevatorFaultService;

    @Autowired
    private ISysUserService userService;

    @Autowired
    private ICommunityManageService communityManageService;

    @Autowired
    private IElevatorInfoService elevatorInfoService;

    @Autowired
    private ISysDictDataService dictDataService;

    @Autowired
    private IRescueRecordService rescueRecordService;

    @Autowired
    private IIntegralConfigService integralConfigService;

    @Autowired
    private IIntegralDetailService integralDetailService;


    /**
     * 查询小区及电梯列表(暂留)
     */
    @GetMapping("/selectCommunityElevatorList")
    @ResponseBody
    public Map<String, Object> reportElevatorTiring(String token) {
        List<CommunityManage> communityList = new ArrayList<>();
        SysUser sysUser = userService.selectUserById(getUserId(token));
        //无归属ID，为平台管理人员,返回空
        if (sysUser == null || StringUtils.isNull(sysUser.getAttrId())) {
            return success(communityList);
        }
        SysRole sysRole = userService.checkUserRoleByAttrId(sysUser.getAttrId());
        if (sysRole == null || StringUtils.isEmpty(sysRole.getRoleKey()) || !(sysRole.getRoleKey().equals(BusinessConstants.COMPANY))) {
            return error(Constants.UNVERIFY, "角色错误");
        }
        //查询该用户所在公司底下的社区
        List<CommunityManage> communityManageList = communityManageService.selectCommunityByAttrId(sysUser.getAttrId());
        if (communityManageList == null || communityManageList.size() == 0) {
            return success(communityList);
        }
        List<Long> collect = communityList.stream().map(CommunityManage::getCommunityId).collect(Collectors.toList());
        for (CommunityManage communityManage : communityManageList) {
            ElevatorInfo elevatorInfo = new ElevatorInfo() {{
                setBelongCommunity(String.valueOf(communityManage.getCommunityId()));
            }};
            List<ElevatorInfo> list = elevatorInfoService.list(elevatorInfo,collect);
            communityManage.setElevatorInfoList(list);
            communityManage.setElevatorInfoNum(list.size());
        }
        communityList.addAll(communityManageList);
        return success(communityList);
    }

    /**
     * 上报困人
     */
    @PostMapping("/reportElevatorTiring")
    @ResponseBody
    public Map<String, Object> reportElevatorTiring(String token, ElevatorTiring elevatorTiring) {
        if (elevatorTiring.getElevatorId() == null) {
            return error(Constants.UNVERIFY, "未选择电梯");
        }
        //避免电梯同时上报问题
        LambdaQueryWrapper<ElevatorTiring> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ElevatorTiring::getElevatorId, elevatorTiring.getElevatorId());
        List<ElevatorTiring> tiringList = elevatorTiringService.list(wrapper);
        for (ElevatorTiring tiring : tiringList) {
            if (!tiring.getTiringState().equals("5")) {
                return error(Constants.UNVERIFY, "当前困人已上报");
            }
        }
        ElevatorInfo elevatorInfo = elevatorInfoService.getById(elevatorTiring.getElevatorId());
        if (elevatorInfo == null) {
            return error(Constants.UNVERIFY, "电梯不存在");
        }
        //电梯名称
        elevatorTiring.setElevatorName(elevatorInfo.getElevatorName());
        //上报人
        SysUser sysUser = userService.selectUserById(getUserId(token));
        if (sysUser == null) {
            return error(Constants.UNVERIFY, "用户不存在");
        }
        elevatorTiring.setReportMan(sysUser.getUserName());
        //困人单号
        elevatorTiring.setTiringCode("KR".concat(String.valueOf(IdUtils.getPrimaryKey())));
        //困人类型(0:人工上报;1:非平层停靠困人;2:不开门困人)
        elevatorTiring.setTiringType("0");
        //上报时间
        elevatorTiring.setReportTime(DateUtil.date());
        //状态（0:上报困人;1:启动救援;2:接受任务;3:到达现场;4:完成救援;5:确认完成）
        elevatorTiring.setTiringState("0");
        elevatorTiring.setCreateBy(sysUser.getUserName());
        elevatorTiringService.save(elevatorTiring);
        //上报困人记录
        RescueRecord rescueRecord = new RescueRecord();
        rescueRecord.setTiringId(elevatorTiring.getTiringId());
        rescueRecord.setTiringState("0");
        rescueRecord.setCreateBy(sysUser.getUserName());
        rescueRecord.setCreateTime(DateUtil.date());
        boolean save = rescueRecordService.save(rescueRecord);
        if (save){
            //添加积分
            //获取上报故障积分
            String score = integralConfigService.getScoreByType(sysUser.getAttrId(),"2");
            //避免输出科学计数法并去除末尾零
            sysUser.setOwnScore(NumberUtil.add(sysUser.getOwnScore(),score).stripTrailingZeros().toPlainString());
            userService.updateUserInfo(sysUser);
            //生成积分明细
            IntegralDetail integralDetail = new IntegralDetail();
            integralDetail.setDetailTitle("上报困人");
            integralDetail.setScoreType("0");
            integralDetail.setChangeScore("+"+score);
            integralDetail.setUserId(sysUser.getUserId());
            integralDetail.setCreateBy(sysUser.getUserName());
            integralDetail.setCreateTime(DateUtil.date());
            integralDetailService.save(integralDetail);
            //获取该公司的所有的维保工程师和维保经理
            List<SysUser> userList = userService.selectCompanyManagerAndEngineer(getUserId(token));
            if (CollUtil.isNotEmpty(userList)){
                for (SysUser user : userList) {
                    if (StringUtils.isNotEmpty(user.getCid())){
                        GeTuiUtils.singlePush(user.getCid(),elevatorTiring.getElevatorName(),"上报困人 "+elevatorTiring.getElevatorName(),"/pages/tabbar/polling/Sleepy/Sleepy");
                    }
                }
            }
            return success(elevatorTiring);
        }else {
            return error(Constants.UNVERIFY,"上报失败");
        }
    }

    /**
     * 告警信息-困人信息列表
     */
    @GetMapping("/elevatorTiringList")
    @ResponseBody
    public Map<String, Object> elevatorTiringList(String token, Integer pageNum, Integer pageSize) {
        //获取用户角色列表
        String userRoles = userService.selectUserRole(getUserId(token));
        SysUser sysUser = userService.selectUserById(getUserId(token));
        ElevatorTiring elevatorTiring = new ElevatorTiring();
        List<ElevatorTiring> elevatorTiringList = new ArrayList<>();
        List<ElevatorTiring> tiringList = new ArrayList<>();
        Map<String,Object> params = new HashMap<>();
        //判断是用户角色
        if (userRoles.contains(BusinessConstants.COMPANY) || userRoles.contains(BusinessConstants.KEEP_MANAGER)) {//维保经理或公司管理员
            params.put("type", "1");
            elevatorTiring.setParams(params);
            elevatorTiring.setCompanyId(sysUser.getAttrId());
            tiringList = elevatorTiringService.selectElevatorTiringList(elevatorTiring);
            for (ElevatorTiring tiring : tiringList) {
                //最终展示没有接收救援的与需要确认的与自己救援
                if (tiring.getTiringState().equals("0") || tiring.getTiringState().equals("4")){
                    elevatorTiringList.add(tiring);
                }else if (tiring.getRescueUserId().intValue() == sysUser.getUserId().intValue()){
                    elevatorTiringList.add(tiring);
                }
            }
        }else {
            params.put("type", "2");
            elevatorTiring.setParams(params);
            elevatorTiring.setCompanyId(sysUser.getAttrId());
            tiringList = elevatorTiringService.selectElevatorTiringList(elevatorTiring);
            for (ElevatorTiring tiring : tiringList) {
                //最终展示没有接收救援的与自己救援的
                if (tiring.getTiringState().equals("0")){
                    elevatorTiringList.add(tiring);
                }else if (tiring.getRescueUserId().intValue() == sysUser.getUserId().intValue()){
                    elevatorTiringList.add(tiring);
                }
            }
        }
        for (ElevatorTiring tiring : tiringList) {
            //困人类型
            if (StringUtils.isNotEmpty(tiring.getTiringType())) {
                if (tiring.getTiringType().equals("0")) {
                    tiring.setTiringType("人工上报");
                } else if (tiring.getTiringType().equals("1")) {
                    tiring.setTiringType("非平层停靠困人");
                } else if (tiring.getTiringType().equals("2")) {
                    tiring.setTiringType("不开门困人");
                }
            }
            //困人时长
            String datePoor = DateUtils.getDatePoor(DateUtil.date(), tiring.getReportTime());
            tiring.setTiringDuration(datePoor);
        }
        //按照上报时间倒叙
        List<ElevatorTiring> collect = elevatorTiringList.stream().sorted(Comparator.comparing(ElevatorTiring::getReportTime).reversed()).collect(Collectors.toList());
        //假分页
        Map<String, Object> mapReturn = new HashMap<>();
        PageInfo pageList = getPageList(pageNum, pageSize, collect);
        mapReturn.put("list",pageList.getList());
        mapReturn.put("pageNum",pageNum);
        mapReturn.put("total",new PageInfo(pageList.getList()).getTotal());
        return success(mapReturn);
    }

    /**
     * 告警信息-困人信息列表数量
     */
    @GetMapping("/elevatorTiringListNum")
    @ResponseBody
    public Map<String, Object> elevatorTiringListNum(String token) {
        //获取用户角色列表
        String userRoles = userService.selectUserRole(getUserId(token));
        //判断是否维保经理
        List<ElevatorTiring> tiringList = new ArrayList<>();
        ElevatorTiring elevatorTiring = new ElevatorTiring();
        SysUser sysUser = userService.selectUserById(getUserId(token));
        Map<String,Object> params = new HashMap<>();
        List<ElevatorTiring> elevatorTiringList = new ArrayList<>();
        if (userRoles.contains(BusinessConstants.KEEP_MANAGER)) {//是维保经理
            params.put("type", "1");
            elevatorTiring.setParams(params);
            elevatorTiring.setCompanyId(sysUser.getAttrId());
            tiringList = elevatorTiringService.selectElevatorTiringList(elevatorTiring);
            for (ElevatorTiring tiring : tiringList) {
                //最终展示没有接收救援的与自己救援的
                if (tiring.getTiringState().equals("0") || tiring.getTiringState().equals("4")){
                    elevatorTiringList.add(tiring);
                }else if (tiring.getRescueUserId().intValue() == sysUser.getUserId().intValue()){
                    elevatorTiringList.add(tiring);
                }
            }
        }else {
            params.put("type", "2");
            elevatorTiring.setParams(params);
            elevatorTiring.setCompanyId(sysUser.getAttrId());
            tiringList = elevatorTiringService.selectElevatorTiringList(elevatorTiring);
            for (ElevatorTiring tiring : tiringList) {
                //最终展示没有接收救援的与自己救援的
                if (tiring.getTiringState().equals("0")){
                    elevatorTiringList.add(tiring);
                }else if (tiring.getRescueUserId().intValue() == sysUser.getUserId().intValue()){
                    elevatorTiringList.add(tiring);
                }
            }
        }
        Integer count = 0;
        if (tiringList != null && tiringList.size() != 0){
            count = elevatorTiringList.size();
        }

        //首页故障数量
        ElevatorFault fault = new ElevatorFault();
        fault.setCompanyId(sysUser.getAttrId());
        List<ElevatorFault> faultList = elevatorFaultService.selectElevatorFaultList(fault);

        Map<String,Object> map = new HashMap<>();

        map.put("tiringCount",count);
        map.put("faultCount",faultList.size());

        return success(map);
    }

    /**
     * 告警信息-困人记录列表
     */
    @GetMapping("/elevatorTiringRecordList")
    @ResponseBody
    public Map<String, Object> elevatorTiringRecordList(Long elevatorId, Integer pageNum, Integer pageSize) {
        startPage(pageNum, pageSize, "create_time DESC");

        ElevatorTiring elevatorTiring = new ElevatorTiring().setElevatorId(elevatorId);
        List<ElevatorTiring> tiringList = elevatorTiringService.list(elevatorTiring);
        for (ElevatorTiring tiring : tiringList) {
            //困人类型
            if (StringUtils.isNotEmpty(tiring.getTiringType())) {
                if (tiring.getTiringType().equals("0")) {
                    tiring.setTiringType("人工上报");
                } else if (tiring.getTiringType().equals("1")) {
                    tiring.setTiringType("非平层停靠困人");
                } else if (tiring.getTiringType().equals("2")) {
                    tiring.setTiringType("不开门困人");
                }
            }
            //困人状态
            if (StringUtils.isNotEmpty(tiring.getTiringState())) {
                tiring.setTiringState(dictDataService.selectDictLabel(BusinessConstants.BUSINESS_TIRING_STATE, tiring.getTiringState()));
            }
            //困人时长
            String datePoor = DateUtils.getDatePoor(DateUtil.date(), tiring.getReportTime());
            tiring.setTiringDuration(datePoor);
        }
        Map<String, Object> mapReturn = new HashMap<>();
        mapReturn.put("pageNum", pageNum);
        mapReturn.put("list", tiringList);
        mapReturn.put("total", new PageInfo<>(tiringList).getTotal());
        return success(mapReturn);
    }

    /**
     * 查看困人详情接口
     *
     * @param tiringId 困人数据ID
     */
    @GetMapping("/elevatorTiringInfo")
    @ResponseBody
    public Map<String, Object> elevatorTiringInfo(Long tiringId) {
        if (tiringId == null) {
            return error(Constants.UNVERIFY, "参数有误:ID为空");
        }
        ElevatorTiring elevatorTiring = elevatorTiringService.getById(tiringId);
        if (elevatorTiring == null) {
            return error(Constants.UNVERIFY, "未查到上报困人数据");
        }
        //救援记录
        LambdaQueryWrapper<RescueRecord> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(RescueRecord::getTiringId, tiringId);
        wrapper.ne(RescueRecord::getTiringState, "0");
        wrapper.ne(RescueRecord::getTiringState, "1");
        List<RescueRecord> rescueRecordList = rescueRecordService.list(wrapper);
        if (rescueRecordList != null && rescueRecordList.size() != 0) {
            for (RescueRecord rescueRecord : rescueRecordList) {
                rescueRecord.setTiringState(dictDataService.selectDictLabel(BusinessConstants.BUSINESS_TIRING_STATE, rescueRecord.getTiringState()));
                //救援人员信息(救援记录)
                rescueRecord.setUser(userService.selectUserById(rescueRecord.getUserId()));
            }
        }
        elevatorTiring.setRescueRecordList(rescueRecordList);
        //困人类别
        if (StringUtils.isNotEmpty(elevatorTiring.getTiringType())) {
            if (elevatorTiring.getTiringType().equals("0")) {
                elevatorTiring.setTiringType("人工上报");
            } else if (elevatorTiring.getTiringType().equals("1")) {
                elevatorTiring.setTiringType("非平层停靠困人");
            } else if (elevatorTiring.getTiringType().equals("2")) {
                elevatorTiring.setTiringType("不开门困人");
            }
        }
        //困人原因
        if (StringUtils.isNotEmpty(elevatorTiring.getTiringCause())) {
            elevatorTiring.setTiringCause(dictDataService.selectDictLabel(BusinessConstants.BUSINESS_TIRING_CAUSE, elevatorTiring.getTiringCause()));
        }
        //救援人信息
        if (elevatorTiring.getRescueUserId() != null) {
            SysUser user = userService.selectUserById(elevatorTiring.getRescueUserId());
            elevatorTiring.setUser(user);
        }
        return success(elevatorTiring);
    }

    /**
     * 是否被人接收
     *
     * @param tiringId
     * @param userId
     * @return
     */
    private boolean isOtherExistReceive(Long tiringId, Long userId) {
        //判断是否有人已经任务
        LambdaQueryWrapper<RescueRecord> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(RescueRecord::getTiringId, tiringId);
        wrapper.ne(RescueRecord::getTiringState, "0");
        List<RescueRecord> rescueRecordList = rescueRecordService.list(wrapper);
        if (rescueRecordList != null && rescueRecordList.size() != 0) {
            //判断是不是自己接收的救援任务
            if (!rescueRecordList.get(0).getUserId().equals(userId)) {
                return true;
            }
        }
        return false;
    }

    /**
     * 开始救援
     */
    @PostMapping("/starRescue")
    @ResponseBody
    public Map<String, Object> starRescue(String token, Long tiringId, String longitudeStart, String latitudeStart) {
        SysUser sysUser = userService.selectUserById(getUserId(token));
        if (sysUser == null) {
            return error(Constants.UNVERIFY, "用户不存在");
        }
        ElevatorTiring elevatorTiring = elevatorTiringService.getById(tiringId);
        if (elevatorTiring == null) {
            return error(Constants.UNVERIFY, "困人信息错误");
        }
        if (elevatorTiring.getRescueUserId() != null ){
            if (!elevatorTiring.getRescueUserId().equals(sysUser.getUserId())){
                return error(Constants.UNVERIFY, "已经有人正在进行救援任务");
            }
        }else {
            //启动救援
            RescueRecord rescueRecord = new RescueRecord();
            rescueRecord.setUserId(sysUser.getUserId());
            rescueRecord.setTiringId(tiringId);
            rescueRecord.setTiringState("1");
            rescueRecord.setCreateBy(sysUser.getUserName());
            rescueRecord.setCreateTime(DateUtil.date());
            rescueRecordService.save(rescueRecord);
            //接收任务
            rescueRecord.setTiringState("2");
            rescueRecord.setCreateTime(DateUtil.date());
            rescueRecord.setRemark("已接受救援任务");
            rescueRecordService.save(rescueRecord);
            elevatorTiring.setTiringState("2");
            elevatorTiring.setLongitudeStart(longitudeStart);
            elevatorTiring.setLatitudeStart(latitudeStart);
            elevatorTiring.setRescuePeople(sysUser.getUserName());
            elevatorTiring.setRescueSign("0");

            elevatorTiring.setRescueUserId(sysUser.getUserId());
            elevatorTiring.setRescueTime(DateUtil.date());
            elevatorTiringService.updateById(elevatorTiring);
        }
        return success();
    }

    /**
     * 救援签到
     */
    @PostMapping("/rescueSign")
    @ResponseBody
    public Map<String, Object> rescueSign(String token, Long tiringId, String longitudeEnd, String latitudeEnd) {
        SysUser sysUser = userService.selectUserById(getUserId(token));
        if (sysUser == null) {
            return error(Constants.UNVERIFY, "用户不存在");
        }
        ElevatorTiring elevatorTiring = elevatorTiringService.getById(tiringId);
        if (elevatorTiring == null) {
            return error(Constants.UNVERIFY, "困人信息错误");
        }
        if (elevatorTiring.getRescueUserId() == null ){
            return error(Constants.UNVERIFY, "任务没有被接收");
        }
        if (!elevatorTiring.getRescueUserId().equals(getUserId(token))){
            return error(Constants.UNVERIFY, "已经有人正在进行救援任务");
        }
        if (elevatorTiring.getRescueSign().equals("0")) {
            elevatorTiring.setLongitudeEnd(longitudeEnd);
            elevatorTiring.setLatitudeEnd(latitudeEnd);
            elevatorTiring.setRescueSign("1");
            elevatorTiring.setTiringState("3");
            elevatorTiringService.updateById(elevatorTiring);
            //到达现场
            RescueRecord rescueRecord = new RescueRecord();
            rescueRecord.setUserId(sysUser.getUserId());
            rescueRecord.setTiringId(tiringId);
            rescueRecord.setTiringState("3");
            rescueRecord.setCreateBy(sysUser.getUserName());
            rescueRecord.setCreateTime(DateUtil.date());
            rescueRecord.setRemark("已赶往救援现场");
            rescueRecordService.save(rescueRecord);
        }
        return success();
    }

    /**
     * 救援完成
     */
    @PostMapping("/rescueComplete")
    @ResponseBody
    public Map<String, Object> rescueComplete(String token, Long tiringId, String rescuePeopleSign, String tiringDescribe) {
        SysUser sysUser = userService.selectUserById(getUserId(token));
        if (sysUser == null) {
            return error(Constants.UNVERIFY, "用户不存在");
        }
        ElevatorTiring elevatorTiring = elevatorTiringService.getById(tiringId);
        if (elevatorTiring == null) {
            return error(Constants.UNVERIFY, "困人信息错误");
        }
        if (elevatorTiring.getRescueUserId() == null ){
            return error(Constants.UNVERIFY, "任务没有被接收");
        }
        if (!elevatorTiring.getRescueUserId().equals(getUserId(token))){
            return error(Constants.UNVERIFY, "已经有人正在进行救援任务");
        }
        elevatorTiring.setRescuePeopleSign(rescuePeopleSign);
        elevatorTiring.setTiringDescribe(tiringDescribe);
        elevatorTiring.setCompleteTime(DateUtil.date());
        elevatorTiring.setTiringState("4");
        elevatorTiring.setTiringDuration(DateUtils.getDatePoor(elevatorTiring.getCompleteTime(), elevatorTiring.getReportTime()));
        elevatorTiringService.updateById(elevatorTiring);
        //完成救援111
        RescueRecord rescueRecord = new RescueRecord();
        rescueRecord.setUserId(sysUser.getUserId());
        rescueRecord.setTiringId(tiringId);
        rescueRecord.setTiringState("4");
        rescueRecord.setCreateBy(sysUser.getUserName());
        rescueRecord.setCreateTime(DateUtil.date());
        rescueRecord.setRemark("已成功解救");
        rescueRecordService.save(rescueRecord);

        return success();
    }

    /**
     * 确认完成
     */
    @PostMapping("/confirmComplete")
    @ResponseBody
    public Map<String, Object> confirmComplete(String token, Long tiringId, String confirmPeople, String confirmPeopleSign, String isApproved) {
        SysUser sysUser = userService.selectUserById(getUserId(token));
        if (sysUser == null) {
            return error(Constants.UNVERIFY, "用户不存在");
        }
        ElevatorTiring elevatorTiring = elevatorTiringService.getById(tiringId);
        if (elevatorTiring == null) {
            return error(Constants.UNVERIFY, "困人信息错误");
        }
        //先判断救援是否完成
        LambdaQueryWrapper<RescueRecord> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(RescueRecord::getTiringId, tiringId);
        wrapper.eq(RescueRecord::getTiringState, "4");
        RescueRecord recordServiceOne = rescueRecordService.getOne(wrapper);
        if (recordServiceOne == null) {
            return error(Constants.UNVERIFY, "救援任务未完成");
        }
        //是否已确认
        LambdaQueryWrapper<RescueRecord> wrapper2 = new LambdaQueryWrapper<>();
        wrapper2.eq(RescueRecord::getTiringId, tiringId);
        wrapper2.eq(RescueRecord::getTiringState, "5");
        RescueRecord recordServiceTow = rescueRecordService.getOne(wrapper2);
        if (recordServiceTow != null) {
            return error(Constants.UNVERIFY, "救援任务已被确认");
        }
        //查询用户角色列
        String userRoles = userService.selectUserRole(sysUser.getUserId());
        //判断是否为维修经理
        if (!userRoles.contains(BusinessConstants.KEEP_MANAGER)) {
            return error(Constants.UNVERIFY, "该用户不是维保经理");
        }
        elevatorTiring.setConfirmPeople(confirmPeople);
        elevatorTiring.setConfirmPeopleSign(confirmPeopleSign);
        elevatorTiring.setIsApproved(isApproved);
        elevatorTiring.setTiringState("5");
        elevatorTiringService.updateById(elevatorTiring);
        //确认完成
        RescueRecord rescueRecord = new RescueRecord();
        rescueRecord.setUserId(sysUser.getUserId());
        rescueRecord.setTiringId(tiringId);
        rescueRecord.setTiringState("5");
        rescueRecord.setCreateBy(sysUser.getUserName());
        rescueRecord.setCreateTime(DateUtil.date());
        rescueRecord.setRemark("确认救援任务已完成");
        rescueRecordService.save(rescueRecord);
        return success();
    }

    /**
     * 我的救援列表
     */
    @GetMapping("/myRescueList")
    @ResponseBody
    public Map<String, Object> myRescueList(String token, Integer pageNum, Integer pageSize) {
        startPage(pageNum, pageSize, "create_time DESC");
        SysUser sysUser = userService.selectUserById(getUserId(token));
        if (sysUser == null) {
            return error(Constants.UNVERIFY, "用户不存在");
        }
        List<ElevatorTiring> myRescueList = elevatorTiringService.findMyRescueList(sysUser.getUserId());
        Map<String, Object> mapReturn = new HashMap<>();
        mapReturn.put("pageNum", pageNum);
        mapReturn.put("list", myRescueList);
        mapReturn.put("total", new PageInfo<>(myRescueList).getTotal());
        return success(mapReturn);
    }
}
